package stephen.teamwork13;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AddCommodity
 */
public class AddCommodity extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddCommodity() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String name=request.getParameter("name");
		String number=request.getParameter("number");
		String price=request.getParameter("price");
		System.out.println("name="+name+"   number="+number+"    price="+price);
		
		if(name!=""&&number!=""&&price!=""){	 //不等于 				   
			UserService us=new UserService();
		    User u=new User();
		    boolean result=false;        
		  try {
			result=us.commodity(u);
			
		  } catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();       
		  }
		    if(result){
			response.sendRedirect("aaCommodityPutSuccess.html");
		    }
		    else{
			response.sendRedirect("aaCommodityPutFail.html");
		    }
		}
		else{
			response.sendRedirect("aaCommodityFail.html");
	}	
		
		
		
		
		
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
